package shujuku;

import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.aierjun.notepadjun.MainActivity;
import com.aierjun.notepadjun.R;

/**
 * Created by Administrator on 2016/6/24.
 */
public class HelperActivity extends Activity{
    private DBhelper dBhelper;
    private EditText btn1,btn2;
    private TextView btnerror;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.zhuce_activity);
        final Button btn = (Button) findViewById(R.id.go);
        findView();

        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String codezhang = btn1.getText().toString();
                String codemi = btn2.getText().toString();
                if (codezhang.length()!=0&&codemi.length()!=0){
                    btnerror.setVisibility(View.GONE);
                    dBhelper=new DBhelper(HelperActivity.this,"Test.db",null,1);
                    SQLiteDatabase db=dBhelper.getWritableDatabase();
                    ContentValues values=new ContentValues();
                    values.put("accounts",btn1.getText().toString());
                    values.put("password",btn2.getText().toString());
                    db.insert("test",null,values);
                    startActivity(new Intent(HelperActivity.this, MainActivity.class));}
                else{
                    btn1.requestFocus();
                    btnerror.setVisibility(View.VISIBLE);}
            }
        });
    }
    protected void findView(){
        btn1= (EditText) findViewById(R.id.verify_code_et);
        btn2= (EditText) findViewById(R.id.verify_code_mb);
        btnerror= (TextView) findViewById(R.id.yanzheng_error_message);
    }

    /*private boolean isValidVerifyCode(String code){
        int value = Integer.parseInt(code);                //将字符串转化为int型
        return value % 10 + value / 10 % 10 + value / 100 % 10 + value / 1000 % 10 == 20;
    }*/

}
